#include <stdio.h>
#include "simpio.h"
#include "strlib.h"
#include <string.h>

bool isMeasurable(int target, int weights[], int nWeights);

#define SENTINEL_VALUE -1

main(){
	int weight, weights[10], i, j = 0, target = 0, nWeights = 0, answer;

	for(i = 0; i < 10; i++){
		weights[i] = 0;
	}
	
	printf("Give available weights, finish with -1\n");

	while(TRUE){
		weight = GetInteger();
		nWeights++;
	if(weight == SENTINEL_VALUE)
		break;
	else weights[j] = weight;
	j++;
	}

	for(i = 0; i < 10; i++)
		target = target + weights[i];

	for (i=1; i <= target; i++){
		answer = isMeasurable(i, weights, nWeights);
		if(answer == TRUE)
			printf("%d is measurable.\n", i);
		else
			printf("%d is NOT measurable.\n", i);
	}
}

bool isMeasurable(int target, int weights[], int nWeights){
	if(target == 0)
		return TRUE;
	else if(nWeights == 0)
		return FALSE;

		   isMeasurable(target - weights[nWeights - 1], weights, nWeights - 1)
		|| isMeasurable(target + weights[nWeights - 1], weights, nWeights - 1)
		|| isMeasurable(target, weights, nWeights -1);
}

